package com.headfirst.dmp.utils

import java.util.{HashSet, Set}

import redis.clients.jedis._

/**
  * Redis工具类
  */
object RedisUtils {


  //jedis配置文件
  val config = new JedisPoolConfig()
  //最大空闲连接
  config.setMaxIdle(10);
  //最大连接数
  config.setMaxTotal(20);
  //连接有效性检查（连接是否活跃）
  config.setTestOnBorrow(true);

  //  //创建连接池
  //  val pool = new JedisPool(config, "192.168.150.11", 6379, 10000)
  //
  //  //返回一个Jedis对象
  //  def getJedis(): Jedis = {
  //    pool.getResource
  //  }


  /**
    * 使用jedis连接Redis集群
    */

  val hostAndPorts: Set[HostAndPort] = new HashSet[HostAndPort]
  hostAndPorts.add(new HostAndPort("192.168.150.11", 6379))
  hostAndPorts.add(new HostAndPort("192.168.150.12", 6379))
  hostAndPorts.add(new HostAndPort("192.168.150.13", 6379))
  hostAndPorts.add(new HostAndPort("192.168.150.14", 6379))
  hostAndPorts.add(new HostAndPort("192.168.150.15", 6379))
  hostAndPorts.add(new HostAndPort("192.168.150.16", 6379))

  val cluster: JedisCluster = new JedisCluster(hostAndPorts, config)

  //返回cluster操作对象
  def getRedisCluster(): JedisCluster = {
    cluster;
  }


}
